<?php


// Only allow 1 second execution time.
set_time_limit(1);


// Start a session.
session_start();


// PHP error reporting level
error_reporting(E_ALL);


// ---------------------------------------------------------------- Context

// Import framework class
require_once("_library/framework/Context.php");


// Initialize framework
$context = new Context(
    dirname(__FILE__),  // The context basepath ( path to the webroot )
    "/framework"        // The context path under which this context runs
);


// Set log file location
$context->setInitParameter("LOGPATH", "/tmp/php-melange.log");


// Set logger level (DEBUG|INFO|ERROR)
$context->setInitParameter("LOGLEVEL", "DEBUG");


// Set log file location
$context->setInitParameter("USE_CACHE", false);


// Set the cache exclude uris
$context->setInitParameter("CACHE_EXCLUDES", array("/login"));


// Initialize this context.
$context->init();


// --------------------------------------------------------------- Security

// Include the PHP-AAS requirements.
require_once("_library/framework/aas/deploy/Deploy.php");
require_once("_library/framework/aas/realm/MySQLRealm.php");


// Add MySQL authentication realm.
$realm = new MySQLRealm();
$realm->setConnectionName("jeroen");
$realm->setConnectionPassword("jeroen");
$realm->setConnectionURL("localhost/melange");
$realm->setRoleNameCol("rolename");
$realm->setUserCredCol("password");
$realm->setUserNameCol("username");
$realm->setUserRoleTable("user_role");
$realm->setUserTable("user");
$realm->setWhereClause("active=1");
//$realm->setDigest("md5");


// Add 'editor' security collection.
$collection1 = new SecurityCollection();
$collection1->setName("Editor Section");
$collection1->addPattern("/home");


// Add 'editor' constraints.
$constraint1 = new SecurityConstraint();
$constraint1->addCollection($collection1);
$constraint1->addAuthRole("admin");
$constraint1->addAuthRole("editor");


// Create a Login Configuration
$config = new LoginConfig(
    "BASIC", "MySQLRealm", "/login", "/login.php?failed"
);


// Set the security realm for this context.
$context->setRealm($realm);


// Set the loginconfig for this context.
$context->setLoginConfig($config);


// Add the 'editor' constraint for this context.
$context->addConstraint($constraint1);


// --------------------------------------------------------- Error Handling

// Add error pages.
$context->addErrorPage(
    new ErrorPage(Response::SC_UNAUTHORIZED, "/error/aas/all.php"));

$context->addErrorPage(
    new ErrorPage(Response::SC_FORBIDDEN, "/error/aas/all.php"));

$context->addErrorPage(
    new ErrorPage(Response::SC_NOT_FOUND, "/error/aas/all.php"));    

    
// -------------------------------------------------------------------- MVC    
    
// Set the test-app/cms + PHP-CMS MVC mappings
$context->setInitParameter("config",
    "_application/resource/mvc-config.php");


// ---------------------------------------------------------------- Process

// Start processing.
$context->process();


// ------------------------------------------------------- Example Settings

/**
 * Base Site URL
 *
 * URL to your Framework root. Typically this will be your base URL,
 * WITHOUT a trailing slash:
 *
 * http://www.your-site.com
 */
//$context->setInitParameter("BASE_URL", "http://imac.local:8888");


/**
 * Context path
 *
 * Path section after BASE_URL
 * WITHOUT a trailing slash
 */
//$context->setInitParameter("CONTEXT_PATH", "/framework");


/**
 * Base Framework directory
 *
 * Path to your Framework root.
 */
//$context->setInitParameter("BASE_PATH", "_library/framework");


/**
 * Default content type
 */
//$context->setInitParameter("CONTENT_TYPE", "text/xml");

?>